package com.choosefine.it.base;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import com.choosefine.it.common.exception.BusinessException;

/**
 * 全局异常捕获
 * @author guwenwei 
 * @date 2016/11/19
 */
@ControllerAdvice
public class GlobalDefaultException extends BaseController {
	Logger logger = LoggerFactory.getLogger(GlobalDefaultException.class);
	
	/**
	 * 异常跳转捕获
	 */
	@ExceptionHandler(value ={BusinessException.class,Exception.class})
	public String defaultExceptionHandler(HttpServletRequest req,BusinessException e){
		logger.error("------------全局异常--------> "+e.getMessage());
		return responseFail(Integer.parseInt(e.getStatusCode()), e.getMessage());
//		return getInstanceJsonResult(null, e.getMessage(), ResultCode.FAILED);
	}
}
